package com.wtwd.campus.receiver;

import com.wtwd.campus.entity.MqIpAndPortResult;
import com.wtwd.campus.entity.MqLocationData;
import com.wtwd.campus.service.IRMFeignClientService;
import com.wtwd.campus.service.InjectFeignService;
import com.wtwd.campus.utils.LocationUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

public class SetTemporaryControlCenterReceiver implements Receiver {
    @Autowired
    private IRMFeignClientService irmFeignClientService;

    @Override
    public String parseMessage(String data) {
        // *WT,800115470000876,V4,S23,111006,112.74.176.68:9099,111012,V,0.0000,S,0.0000,W,0.00,0,160621,FDFFFFFF
        String[] split = data.split(",");
        String imei = split[1];
        String messageType = split[2];
        String type = split[3];
        String commandNumber = split[4];
        String ip= split[5].split(":")[0];
        String port = split[5].split(":")[1];
        String time = split[6];//指令返回信息的时间
        String lat = split[8];
        String lng = split[10];
        String speed = split[12];
        String orientation = split[13];
        String date = split[14];
        String deviceStatus = split[15];
        List<Double> list = LocationUtils.transiformLatAndLng(lng, lat);
        MqIpAndPortResult mqIpAndPortResult = new MqIpAndPortResult();
        mqIpAndPortResult.setImei(imei);
        mqIpAndPortResult.setCommandNumber(commandNumber);
        mqIpAndPortResult.setDeviceDate(date);
        mqIpAndPortResult.setDeviceStatus(deviceStatus);
        mqIpAndPortResult.setDeviceTime(time);
        mqIpAndPortResult.setIp(ip);
        mqIpAndPortResult.setPort(Integer.parseInt(port));
        MqLocationData mqLocationData = new MqLocationData();
        mqLocationData.setOrientation(Integer.parseInt(orientation));
        mqLocationData.setSpeed(Double.parseDouble(speed));
        mqLocationData.setLatitude(list.get(1));
        mqLocationData.setLongitude(list.get(0));
        mqIpAndPortResult.setMqLocationData(mqLocationData);
        InjectFeignService.getIrmFeignClientService().tempControlCenterResponse(mqIpAndPortResult);
        return imei;
    }
}
